factor out superfluous chdirs