cd handling and some more refactoring.