Updated code based on review comments