writes output into subdirectories