added changes to make stack independent of the initialized function (more modular)