Fixed some error handeling