Syntax changes, made loops more concise, added comments.