RPC: changed error handling
rpc: code refactoring