Code cleanup and added more comments.