Removed `expect` chains

Cleaned up `expect` chains and extracted empty directory check to a
separate file.