fixed collision detection and various other improvements