Added JSON output and fixed a small bug