Refactored database init