Log/error handling refactoring for labeling.