Added cache, result counter, fixed bugs