Refactored package so that av_state is no longer a global variable. This allows multiple var calculations at the same time.