finish python implementation