Some minor fixes / memory cleanup