implementation in python, quickier, simpler