Complete rewrite of package. Much better API.