added comments, condensed code, it still works