Fix out of order code, fixes issue with portable mode creating invalid files