Code clean up, added comments