Improved the mouse collision code