code cleaning and small speed increases
add the beginnings of a killer test suite