Fixed memory deallocation issue and changed some code to follow the llvm coding style.