cleanup and add some more comments