Move directory check to correct point