Added counter
Updated error handling
Optimized Logging