major code refactor, fixed movement detection