Squashed some bugs.
Implemented some suggestions from johnraff