Fixed some bugs with collision detection