First almost working version based on files