Begin refactoring for proper error management