cleaned up onSubmit and added more comments