added comments, condensed code base