refactored to implement preview plugin with caching