Precalculus template refactoring