Corrected some issues revealed by sonar