security.c: Rewrite some code