realocate algo working