Speedup

Add a memoize decorator to speed things up.