open file juste one time, and move file responsability into log file
clean code; split loop into small functions
Merge pull request #1 from cafetux/master

open file juste one time, and move file responsability into log file