refactor + bug fix