fixed remain bug done (debug code still exists)