Some minor code tweaks to improve clarity.
Add global options to discard invalid sequences and beep on invalid sequences.