Added support for both XML and JSON and refactored classes