Error callbacks

This should fix #6 and be a generally good thing anyway!

It's also branch from #4.