serialize and deserialize implemented better