Could just collapse lines 143-146 and "return err"