refactor valid? method