Changed bounds detection from pure distance to detecting when outside the box. Simplified the code quite a bit.