Fixed the bug which was affecting convergence of Newton method. Code now seems very robust.
Merge branches 'workingtest' and 'master'