cleaned up valid function