Added code to handle collisions