major cleanup, lots of commenting and whitespace