add error detection condition in main function