added check for castling