The last couple of changes that I made had not been commented properly. Here the comments tidied up + 1 small addition to the search for performance. Instead of toggling a boolean using bool = 1 - bool I substitute the faster & more readable bool = \bool.
Patch created with tortoise SVN! I hope it's alright.