move self.flat branch out of try block