Fixed bug with collision detection