Error handling

Cleaner way of handling errors, I think.