use a temp file for preview
remove debug code