Resubmitting PR #157 in 2.1 branch