Partialy reverted changes from d0085cbf0da8623b6f9ce6fb27a49f25487b901c. Fixes #1631.