some speedup thanks to @elendel-