Move the tilde-expansion code to a better place