finished and tested command generator function