Added some analytics. Refactored