Manually implemented #310 from @Trismegiste.