Did some refactoring and fixed as many FxCop errors as possible.