some changes
add a little memory safety stuff