Refactor and debug String validateImpl