Small updates to query 4, first implementation of query 3, maintenance
and clean-up.