Fixed bugs due to previous refactoring.  Also corrected a long-time enter/exit detection bug