bug fixes from first pass github impl