Refactoring to improve formula script generation.