added serialize errors function