Collision detection and bug fixes