Code cleanup, added comments.