Refactored database control