added code to stop thinking is mate is found