Changed database to use more inline SQL