- memory leak and a few other minor bug fixes as discovered by coverity scan.