Clean-up core implementation, improve fault handling.
Add unit tests.