Refactored for new database design