added simple collision detection function