Removed some logic errors and memory leaks in the project.