Fixed minor permission issues
Fixed a few memory leaks