Simplify implementation, and probably speed things up too.