final version of plugin working with previews