Completely rewritten gravitation and collision detection logic