more validation and minor cleanup