Small refactor of error check