refactored compilation of query