modified the way stdin is read to check for balanced parentheses after each line