fix typos, add memoization, mocha tests