Added NA removal and coercion of X to matrix.