Added test case and fixed #676