Improved type stability and fixed several bugs

* Fixed bugs in the definition of all the divergences
* Improved type stability