many changes for refactoring auto-detect with stdin, other random stuff