Refactor util/mkdef.pl for clearer separation of functionality