optimize some functions in Badger.py