Create preview function moved from Media model to external file