Refactored some db query using the new library