Change branch checking logic

@timurvafin  Ok, I'll fix it