Partially reverting 6bddf239ffc70cd3cb5042f188baf8ad364e45b9 to fix issue #571