Merged most of the code into Addin so that its Application property is available everywhere