Fixed memory leaks
beautifying some variable names and function calls