Added test_stack.py. All tests pass.
Reworked algorithm
update for 3 October 2014