My current implementation is rather slow and it would be cool to try to write a really optimized version of this.