A *really* naive implementation.
Finally a reasonable implementation