rewrote it for python