Added memoization to all functions, extended documentation.