added error handeling