fixed a variety of bugs and overhauled the stats package