refactor content detection / error handling