Fixed some memory protection issues