Refactor to use serialize