Fix `Max call stack size exceeded` error

Add test case