Add branch extraction, refactor