Code cleanup and added comments.