Tidy up server code for better readability
Change some variable and function names