Revert "Simplify code to fix COV 1250448"

This reverts commit d49373bcb3976512266814383acebe86dd02ad32.
Fix CID 1250448
Finish pfs
Fix warning