Added caching.
Added simple thresholding.