Added collision detection mechanism