Added cache and fixed small bug.