Perft testing and some optimizations