fix bugs around path expansion.