Code cleanup and added some comment.