Implemented collision detection