Fix bugs and move a bunch of code to the server
Style update