fixed #6
I confirmed function on a unit test.