check if array key exists before using it