Merged selection stack code