Couldn't quite get Joseph's optimisations to work properly, so rolling back while I investigate further...
Implemented some of Joseph's changes in my original source: moved getIndex into solver class and changed dodgy doubles into correct integers