added server code for completeness