Refactoring for efficiency with large numbers