Refactoring of make prg function