Refactored database loading