implement loop stack