Add toObject function.