Mass code refactor

With the help of ReSharper.

Also upgraded framework from .NET 4.5.1 to 4.5.2
msdn.microsoft.com/en-us/library/ms171868(v=vs.110).aspx#v452