Checking and creating needed directories only once.