fixed nullpointer issue and waitforenter bad behavior