New criteria for ergodicity and nonuniform hyperbolicity