Fixes from @maurycyp and work from there