Two functions seem to work well.