some optimisation; moving queries into classes to make sure they are consistent, efficient, and use caching.