Better process communication and error handling

Fixes #3