added serialize function. Not sure why it fixes