moved duplicate validLine code into separate function
This way the code is just called for each individual line instead of
being duplicated for one line and then for multiple lines.