fix potential bugs indicated by VS code analyzer