Cleaned and improved terminal pattern algorithm and global exception
handling.