Fixed function so that it passes mocha test.