added collision detection