NSA director: Data mining follows law, thwarts terror