added error handelling