Command handling rewrite