newest version, added comments and clarity