Some more memory leaks and codes formatting