major cleanup, but didn't change much actual code