refactored cd retreival to own subroutine