More code cleanup, added comments