Fix bug in castling logic