moved preview function into main js file