add error detection and avoid force quit