collision detection and some minor changes