Refactor: Replace atom with a local ref