bug and error handeling fixes