Finished security work. Fixed bugs.

Several minor bugs were fixed.
Security functions like change password and grant security were fully
implemented.
Email notifications were refined and expanded.
Code clean-up began.