fixed image preview code