Revert "abstract logic into function"

This reverts commit 8c6e89b8c9bdd6b1ba5db609e678f7a2aa7bb8c5.