Use checkPos to check if the position is valid (the original code was wrong).