working on #6 and #13.

Tests implemented, and fitting appears to work, using L-BFGS-B