Made a few changes to handle middleware and server better.