Modified code snippet per chengyu's suggestion