Major simplification of expand_tilde function