Remove unused variable
Some refactoring of confusing code