partial revert of 8db6b816 and 946d5348