Code reorganization

No functional changes, just rearranged functions to make the code easier
to follow.
Fixed changing runenv/metadata settings

In the confirmation screen, changing runenv/metadata insertion from YES
to NO was not working. Fixed.