fixed the collision bug, code clean up and documentation