Start of translating to using databases. Changed a lot. Won't compile but gives a starting point for Phase 3.