Updated code
Adding logging