clean up and add more comments