remove while loop for each script
remove debug and check for r is not None