Refactoring and StyleCop fixes