port from main lib