refactored entire database