server almost finished (but untested)