Move serialization logic to separated package