refactor initialize observer function.