More refactoring. Some speed adjustments.