Some variable name changes, memory leaked fixed