added storing of previously computed values, time went from 48 sec to 0.82 sec