refactor method and code