refactored text input function for simplification