#12: refactored some database-related code