Cleaned up database some more. Refactored a bit