completed stack class refactoring with tests