Refactoring of the analytics code