added more template range logic