refactor singleton design
misc fix
bug fix and refactor