Added tests, fixed the bug in the bug.