Refactor checks for castling