move ended branch method into own method