fixed a bug for valid positions