basic function is finished add more error handing to make the program robust