added allocation check