genericize rolling_median function