properly fix #1257, test cases included