Made the queries more modular and faster.