Major DB and code overhaul