Cleaned up while loop in make_text function