More refactoring. Making JSON support use it now.