freeing resources explicitly, fixing class visibility