Completely rewrite command handling