Refactoring

Centralise the query wrapper, since it'll be referred multiple times.