Added doc blocks, also fixed invalid for each.

There was an invalid foreach exception being thrown as the local
properties where null rather then being arrays.
Fix for not calling the method on query.
clean up a bit