Added function for collision handling