Rewriting some stuff. Added safe functions through libsafec.