Cleaned up very slightly for the public (explained the scary bit).