Refactored to database