Small speedup
More refactoring and speedup