Move stack logic in stack class.