move preview to own function