Fix numba compilation error (fixes #346)
The compilation error is solved. I have added some extra comment and explanation that I think is needed for this complicated section of code. I have also made some small changes in the code but it is nothing that changes that behaviour. The code have been tested with unit tests and some manual integration tests.