Cleanup into bash functions