added some error handeling