Refactor analytics module