input_string function
Refactored to avoid copy paste code
Some checks for efficiency