Made changes as per suggestion above. Please review the patch.
Thanks!