Refactored Database stuff