Query & URL helper functions, refactoring