Migrate from commands to subprocess

We need control over stderr separated from stdout.
Split code to even more functions