finalized the program with error support