fixing a resource leak, plus not null unary operator (?)