Update server code to use generators