SPAM avoided, fixed indentation so error log is not inside for loop.
Added comments to code.