Add missing licence headers and refactor the serializer