switch function replaced by if else blocks (with correct spacing).