     for other in c.neighbors when other[1] <= @maxRadius()
       f(t) for t in other[0].inhabitants
     i[0] for i in ar.sort (a,b) -> a[1] - b[1]
-  cellAt: ( x, y ) -> @cells[ x // @cellWidth ][ y // @cellWidth ]
+  cellAt: ( x, y ) ->
+    x = 0 unless x >= 0
+    y = 0 unless y >= 0
+    w = @cellWidth
+    column = @cells[ div x, w ]
+    return @cellAt( x - 1, y ) unless column
+    cell = column[ div y, w ]
+    return @cellAt( x, y - 1 ) unless cell
+    cell
   # place a thing in the appropriate cell
   place: (thing, onlyMovingIn) ->
     cell = @cellAt thing.x, thing.y

      if influence
        data = @others[other.id]
        d = gd[data]
        influence /= d * d
        influence *= g
        [ xa, ya ] = geo.vector data, influence

        id = t.id
        continue if id == tid || seen[id]
        tp = others[id]
        continue unless tp
        d3 = gd[tp]
        continue unless d3 and d3 <= distance
        sin3 = gd[ tp + 1 ]
        seg3 = gd[ tp + 3 ]
        keep = if seg3 == seg1 or seg3 == seg2
