code overhaul, no functional changes