Adding some optimizations suggested by Alain, and one found together.