rewrote in python