rewrote it using python