Refactor execute_command and move it to the util namespace