Fixed analyzer issues and warnings (#993 and fixed #992)