code cleanup, added comments