Improve security modules and fix several minor bugs.