Refactored Database library