Simplified a bit...need to test more.
satisfactory outputs...but needs refactoring
Getting right outputs and refactored.