Updated method serialize()