optimized code in btsnl.py