python version done; C version sightly modified