Fixed bug in 'latest pacts' code by introducing a DB view