Error handling

WIP - Not ready for merge