Replaced mkdir with makedirs to support nested paths.