Moved input handling to a stack-based state