allocate space correctly