Fixed last folder issue

Now will always find last folder
Added comments to code
Fixed newline issue in log file