fix lastvalidposition handling in isvalid fn