Added better output dir handling