refactored inputhandler