Changed serialize function to return an object, not a JSON string