Unused var cleanup & fix memory leaks