refactored input method