Fix some unit tests, run Perft. Minor code cleanup.