Added a callback function mechanism to provide for early loop exits.