cleanup and add some comments