Refactored common project euler code.