Stupid bug fixing

- opening streams before performing any operations on them
- ensureDirExists returned false for existing dirs instead of checking
  if it is really a dir or file