implemented collision detection