updated while loop with cstring cpy