fix empty stack calculation error