Added serialization, reworking API.