modyfied function apply_surface for clipping