This implementation is currently unoptimised, but much faster then the simple implementation.
This is for testing purposes only, as it is very slow.