Fixed #603.
Added a test set that proves the bug.