Added event system to lessen the use of the main mutex and instead use thread safe data structures (TSLQueue). Also can enable and check events during execution (connect, disconnect, good mode, bad mode). Fixes and refactorings.