Manually merged Atef's changes

Atef added quite a bit, and sent me a previous version with his changes.
I merged his changes with the current version.
There are a few things that need to be managed between his changes and
the main program, but I'll try to handle that.