fixed function and mocha test