Starting code overhaul

overhauling this code - although it might be easier to start from
scratch.