refactor and add public valid() method
refactor tests