Consistent modified gravity: dark energy, acceleration and the absence of cosmic doomsday