UPDATED: made key check more robust