Picked a few of OldDeath's last changes to security and merged them to master.