Major refactoring and cleanup (breaking changes), adapted to newest libraries