Switch to use the heap here, better error reporting on failure.