fix stack closing bug