add directories and fix some logic errors