correct png optimizing. Add wait and correct syntax of while.
correct processing lines for png.
move filename into a variable LOGFILE.