Added code which is used to prevent bad memory allocations.