Added tests. Moved command building out to own fn