Code cleanup, added comments for more clarity