Few memory leakc fixes, few performance microoptimisations reported by cppcheck and some dead code removal