Fixed a few crippling but very subtle bugs.

The second one has had me scratching my head for several weeks now