cleaned up some error handeling