Refactored to use more `goto`s