Update libraries, a ton of related refactoring