cleaning up and added some comments.