add end condition