Major overhaul, still not fully working.