fixed up error handeling