Refactor error handling

lol