Rewritten createPreview function!