Optimized the Quad Tree.

The query functions now use closures instead of creating new funtions
and arrays each time they're called.