Updated code as per review comments.