Refactored and encapsulated Database class