finished first pass of code overhaul