Refactored action logging code to put reused code into functions