restructure query for easier readability