added implementation and mocha tests