Euler 14 refactered