Refactor error handling

:dogemode: