Updated code with new approach