Implement exact matching with ^ and $

^ works only if it is the first character of the pattern and $ works only if it
the last character of the pattern.
Refactor long lines and add support for the Up/Down keys