Fix #542. Also revert issues introduced in c18029e.