Major refactor of the core library.