Preliminary collision detection; misc optimizations