added check to create data directory if needed.