Moved the directory check before prepare