refractor & bug fix