major overhaul to logic and database usage