improved collision detection, but there are still a few bugs... thinking about refactoring code