internal errors should raise an exception instead of generating an error response
move rpc to top-level and sample_apps inside it.