added allocation checks