Refactoring and added more logic to debugging client errors