Refactoring (possibly, speedup)