core rewrite - the library gets more modular