Bug fixes, documentation

Several tweaks and fixes. Added additional command line input options.
Extended comments in all files.