New PR with fixes from comments in #769