refs #64: fixed typos, added memoization, set() are significantly faster than lists (in this case)