Created collision detection function