toObj algorithm working well