Much more compact fix as suggested by pron