lots of coding cleanup