small fixes
fix bug when file turns into dir +  some optimizations