Add test cases for stack and slightly modified implementation