Re-wrote to_query method to use map