Refactor of main fs.js