added stack logic previously lost