Fixed issue #3163, added test cases