Better error handling and stop using private APIs