Fixed stack calculation issues