updated error handeling