improved allocation error handlings.