Added documentation for loop, changed hiddenState to match loop's type signature