Add error handling.
Add debugging function.