Memory leak fixed, various coding style fixes