Refactored euler 6