Adds a unit test and a fix for the bug 697