This commit mostly just moves code around.
Additionally, update build tools so that no stdio redirection is necessary.