revert function refactoring since script did not work afterwards