fixed some leaks and unallowed accesses