refactoring & bug fix