Updated and simlified the library.

Most code comes from MwLibrary.