[Tex/LaTex] How to use Function in latex algorithm

algorithm2ealgorithmicalgorithms

begin{algorithm}
\SetAlgoLined
\DontPrintSemicolon
\KwIn{$ NPs $\Comment*[r]{All Noun Phrases of D}}    
\KwOut{$ {NPs}^{'}$ \Comment*[r]{NPs without PHIs}}
\SetKwFunction{Fun}{PHIsDetection}
\Fun{$NPs, PHIS$}{

   $PHIs \longleftarrow Legislations(HIPAA, i2b2, MIMIC) $;

   ${NPs}^{'}\longleftarrow NPs $;

    \ForEach{$ NP \in NPs $}{
    \If{$ NP_j \in PHIs $}
    {$ NPa_j \longleftarrow g(NP_j) $;}
}

    \Return ${NPs}^{'} $
}
\caption{Algorithm for Detection of PHIs}
\label{PHIDetectionAlgo}
\end{algorithm}

The code Produced:

The above code produce the following output which is in picture.
All I want to correct the indentation, as the code should show within the function. So the line 1 and 9 should move to left.

Best Answer

\begin{algorithm}[H]
\SetAlgoLined
\DontPrintSemicolon
\KwIn{$ F $\Comment*[r]{List of Sensitive Terms}}    
\KwOut{$ S^{*} $ \Comment*[r]{Negation Excluded List}}

    \SetKwFunction{FMain}{NegationDetection}
    \SetKwProg{Fn}{Function}{:}{}
    \Fn{\FMain{$F$}}{
        $ S^{*}  \longleftarrow F $;    

        \ForEach{$ F \in NPs $}
        {\eIf{$ f_i = Negated $}
            {$ N \longleftarrow f_i;$}
            {$ S \longleftarrow f_i;$}

        }
        \textbf{return} $ S^{*}; $ 
}
\textbf{End Function}
\caption{Algorithm for Excluding the Negation}
\label{NagetionAlgo}
\end{algorithm}

enter image description here