imporved allocation error handlings.