refactored the preview script.