cleaned up and added more comments