Added null check for stack.