mild cleanup and fairly extensive comments for function definitions. amazing.