More refactoring and optimizing.
More refactoring and optimizing.