fix bug and use singleton pattern