bug fixing - stack too deep
new algorithm working