Made the reference implementation a bit more readable