Incorporated @shekari's feedback, tests passing. for/hash changed for backward compatibility.