Fix valid() function - returns not valid on the last row before this change.