change use flags and add better error handling