query cleanup, start of refactorings, etc