Added a stack and a sort method