refactor & bug fix