Fixing a stack overflow and logic error in move generation.