Tweaks to fix some code problems. Add explanation.
Fixes from Ryan's feedback.