LPS-45491

Hey Minhchau,

I wasn't sure about where to extract the logic out to (since I didn't want to have duplicated code) or what the name the variables. Let me know if you want some changes done to it or want to resolve the issue in a different manner.

Thanks.