refactor analytics