Port back vtgate.py with style changes and bug fix.
Code clean up