Fixed memory leak, minor changes.