completely rewritten protections code