Query pattern

@imlucas 
Parse can now parse the query pattern field.
+ A bit of refactoring
- moving portions of code into their own function
- spacing
- renaming sort_shape to sortShape