Adding Stack and some refactoring