Refactor valid? method