Refactor and fix.

fixed the bug of singleton.