refactored command execution hooking