Updated to create directories when they are not there