add check on isset() before foreach