Clean up and add some commenting