First refactor, removed the hideous self implementation of json