Added condition checks for adiing gates