Fix `:k` command: add validity checking