refactor some code, add working json api again