Handle checkmate and loss state. Handle 'new' command

Also removed a memory issue and a checkmate test.