moved cave handling code for EM engine to new source file