added memory protection