clean up and added more comments