improved algorithm to determine geohash queries

The new algorithm works as follows:
1. Determine the 8 coordinates with distance of radius from each other that form a bounding box around the desired query circle.
2. Determine how many bits are necessary to receive a geohash with corresponds to a bounding box length of at least radius
3. Calculate the 9 geohash queries for the 8 coordinates and center coordinate using the number of bits calculated in the previous step by flipping the appropriate bit and removing any remainder.
4. Remove any duplicates
In any case the up to 9 queries should contain any geohash that lies within the given circle. I've written tests to ensure the helper functions and the resulting queries work correctly.

The method fails for queries close to the poles. However geohashing fails here in any case (also with the old algorithm), as any coordinate near the pole can be in any range.
I thought so too, until I wrote tests ;) Example: -450 should be wrapped to -90, however (-470 + 180) % 360 == -270, so the result would be -450. The distinction is necessary because modulo does not map to a positive range.