Replaced json_encode with serialize to be more encoding agnostic.