Only create directories when needed. Fixes #4.