tweaked json api and cleaned up code