fixed a couple bugs, moved all to server.py