Major overhaul, untested version