Higher level IPC abstraction (fixes 238)

This is mostly refactoring.

Fixes #238.