Reworked to use one database query