cleanup code, comments, and security fixes.