Clean up and comment code