complex collision detection function implemented