rewrite and merge of py and c files