Added error detection for cd