Porting recent changes from Python lib