Using an if statement to create counter balancing online

Solution for the second error is here (bug fixed):