Added tmp and fixed up dirpath logic