various security fixes and precautionary checks