moved branch detection back