Extract method and delete unrelated code