Refactor invalid_input method