Refactored database access to Loader class