refactor subprocess calls