Significant changes, including small attemt to make ugly matlab code vaguely less terrible.