Fixing potential bug in castling