started fixing coverity issues: memleaks, unintended integer overflow