Fixed a few issues indicated by Sonar