Revert "Removed use of problematic decorator shortcut in scan op." and another useless refactoring in tensor/opt.py

This reverts commit 7558b180ca905495e96016da91cd41a409a5008f.
Fixed if range.