Cleanup code based on static analysis results

Still seeing problems with:

- Event handlers considered declared incorrect (CA1009)
- Not explicitly marking a type as serializable (CA2237)
- Types containing disposable fields don't implement IDisposable
(CA1001)
- Various potential P/Invoke issues