Fixed some errors detected by Code Analysis