made it self-contained, also cleaned up server code