improved stack deletion and emptying