Restructured some parts of bayesact.py for performance improvements