Refacoted into a package, some minor fixes, and some little docs.