Refactored updating the gen_file

Moved the logic for updating the gen_file into a function of its own.