cleaned up and added comments.