Modified some DB queries to better fit the front end requirements