added validate function and tests