Write collision detection
Minor code cleanup