Refactored a lot of the query data type conversion stuff