Added error checking to directory creation