refactor stack example