Refactor command generation to be simpler