Another PR fixes this as these two were worked on simultaneously and it turned out they share significant amout of code: