Add extract and refactor serialize a bit