Bug fix: array arithmetic was wrong in several places.  Tests updated.