updated gui code to include error handling