code refine to make the logic more clear, and remove unnecessary try/catch