Added check for valid api key