refactored existing stack based implementation to use lists instead.