Added error logging
Updated counter to process next file in a directory