[server.py] - rework mainloop to allow for further functionality