rpc: changed error handling
rpc: code refactoring