Reorganize and make a tiny library API.

This makes it importable and callable from Dart.