refactor, bug fix