Refactored  Code to use the Database Class