Refactor some functions in lib/dictionary.js

Hi, I refactored some stuff, have a look at it and merge if you like :)
The tests still pass and test.js produces the same result as before, but I might have misunderstood some parts of your code, so better check all the changes.
Very cool project, by the way, thanks for writing this!