Textbox special keys handling fix and small refactoring