major restructering
more cleanup, better variable names