might be worth DRYing up the extension checking in to a loop over an array.