refactored main database