fixed locking and collision testing

some bugs left in bounds checking.