clean up code and added comments.