Added collision detection code