Moved main functionality to a function
Added option to output to two directories