created utility method
and also added the option to quit early if there's no more work to be done.