Working version of Stone-Wall problem (fixed indices/flags).