added rpc reply handling; putting server code to own file