Cleanup code and added comments.