Fixing bug and unit test, adding unit test