Add test and refactor validation