Moved castling logic