Updated error checking in the engine - error with counting backwards.