Refactoring module level execution into a function