Implement replace in Stack and refactor without using it