refactor complex method