Cleaned up and annotated code for clean up.