Implementing my query function and refactoring my code in my database class