Some refactoring. Working condition.
Lots of debugging of seeming underflow issue.