Updated code based on review