merged version of #2483