Added handling for selection during command mode and better pterFocused cleanup.