Refactored command code

Thanks Nix and slime from #love