Code cleanup, added comments