added arrow key detection and history browsing using up/down arrow key