fixed some bugs with detection when moving