Handle errors better, create parent directories when needed