refactor method and better implementation