Added basic error handling.

Still very incomplete.