doesnt work correctly if length is null