corrected stack impl