rewrote in python :)