improve toStdClass and add tests