Lots of fixes

Fixed a lot, eliminated bad code, and wrote comments. This is 90%
operational. Now comes some more testing and error checking.