changed all todict to to_dict