Made the cd error checking more efficient