fixed again sorting and stack update