Handle empty stack more gracefully