fix issue #2019 and added tests