Used ReSharper to improve the code.