Rewrite, added MySQL compatibility, a simple test.