cleaning and improving the code and making default value for stack