Fixing segfaults, checking for cd change on the fly