Added early stopping code.

Signed-off-by: loganperreault <perreault.logan@gmail.com>