update code according to review comments