Add throws InvalidOperationException and fix duplicate apiKey check
Merge github/master