Updated code to run faster