Added output support and fixed some concurrency issues.