added comments, made code more readable