Some cleanup and changed JSON handling.