added error handling to submit method