Adding further tests to QueryBuilder

Ported the relevant ones and fixed things where necessary