castling: fix two bugs