server code

untested, but error-free