added the function checkIfValid and a unit test for that function