Fix missing check for the existence of index.json before removal. Also write errors to the stderr instead of the stdout.