Fixed two serious logical errors found by jshint, added memoization to suggest.